<template>
  <el-dialog
    :title="!dataForm.mhId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-row>
        <el-col :span="6">
        <el-form-item label="棉花编号" prop="mhBh" v-if="dataForm.mhId">
          <el-input v-model="dataForm.mhBh" placeholder="棉花编号" disabled></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="记录日期" prop="recordDate"v-if="dataForm.mhId">
          <el-input v-model="dataForm.recordDate" placeholder="记录日期" disabled></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item  style="font-size: 12px" label="总株数" prop="mhNumber" v-if="dataForm.mhId">
          <el-input  v-model="dataForm.mhNumber" placeholder="总株数(株)" disabled></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="单结铃数" prop="mhDzjls" v-if="dataForm.mhId">
            <el-input v-model="dataForm.mhDzjls" placeholder="单株结铃数(个)" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="株高" prop="mhHeight">
            <el-input v-model="dataForm.mhHeight" placeholder="株高(cm)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="茎粗" prop="mhJc">
            <el-input v-model="dataForm.mhJc" placeholder="茎粗(mm)"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="叶片数" prop="mhYps">
            <el-input v-model="dataForm.mhYps" placeholder="叶片数(片)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="果枝数" prop="mhGzs">
          <el-input v-model="dataForm.mhGzs" placeholder="果枝数(个)"></el-input>
        </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="果枝节高" prop="mhDygzjgd" >
            <el-input  v-model="dataForm.mhDygzjgd" placeholder="第一果枝节高度(cm)" ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="蕾数" prop="mhLs">
            <el-input v-model="dataForm.mhLs" placeholder="蕾数(个)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="花数" prop="mhHs">
            <el-input v-model="dataForm.mhHs" placeholder="花数(个)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="总铃数" prop="mhZls">
            <el-input v-model="dataForm.mhZls" placeholder="总铃数(个)"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="吐絮数" prop="mhTxs">
            <el-input v-model="dataForm.mhTxs" placeholder="吐絮数(个)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="果枝始节" prop="mhGzsj">
            <el-input v-model="dataForm.mhGzsj" placeholder="果枝始节(节)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="果枝台数" prop="mhGzts">
            <el-input v-model="dataForm.mhGzts" placeholder="果枝台数(个)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="铃长" prop="mhLc">
            <el-input v-model="dataForm.mhLc" placeholder="铃长(cm)"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="铃宽" prop="mhLk">
            <el-input v-model="dataForm.mhLk" placeholder="铃宽(cm)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="铃型" prop="mhLx">
            <el-input v-model="dataForm.mhLx" placeholder="铃型(椭圆形/圆形/长圆形)"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="添加人" prop="mhZz" v-if="dataForm.mhId">
            <el-input v-model="dataForm.addUser" placeholder="添加人" disabled></el-input>
          </el-form-item>
        </el-col>
<!--        <el-col span="6">-->
<!--          <el-form-item label="单铃重(g)" prop="mhDlz">-->
<!--            <el-input v-model="dataForm.mhDlz" placeholder="单铃重（克）"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="籽指(个)" prop="mhZz">-->
<!--            <el-input v-model="dataForm.mhZz" placeholder="籽指"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
      </el-row>

<!--      <el-row>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="籽棉产量" prop="mhZmcl">-->
<!--            <el-input v-model="dataForm.mhZmcl" placeholder="籽棉产量(kg)"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="马克隆值" prop="mhMklz">-->
<!--            <el-input v-model="dataForm.mhMklz" placeholder="马克隆值"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="整齐度(%)" prop="mhZqd">-->
<!--            <el-input v-model="dataForm.mhZqd" placeholder="整齐度"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="比强度" prop="mhBqd">-->
<!--            <el-input v-model="dataForm.mhBqd" placeholder="比强度(CN/tex)"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
<!--      <el-row>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="伸长率(%)" prop="mhSzl">-->
<!--            <el-input v-model="dataForm.mhSzl" placeholder="伸长率"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="反射率(%)" prop="mhFsl">-->
<!--            <el-input v-model="dataForm.mhFsl" placeholder="反射率"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="黄度" prop="mhHd">-->
<!--            <el-input v-model="dataForm.mhHd" placeholder="黄度"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="衣指(个)" prop="mhYz">-->
<!--            <el-input v-model="dataForm.mhYz" placeholder="衣指"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
<!--      <el-row>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="衣分(%)" prop="mhYf" v-if="dataForm.mhId">-->
<!--            <el-input v-model="dataForm.mhYf" placeholder="衣分" disabled></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col span="6">-->
<!--          <el-form-item label="添加人" prop="mhZz" v-if="dataForm.mhId">-->
<!--            <el-input v-model="dataForm.addUser" placeholder="添加人" disabled></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          mhId: 0,
          mhBh: '',
          recordDate: '',
          mhNumber: '',
          mhHeight: '',
          mhJc: '',
          mhYps: '',
          mhDygzjgd: '',
          mhGzs: '',
          mhLs: '',
          mhHs: '',
          mhZls: '',
          mhDzjls: '',
          mhTxs: '',
          mhGzsj: '',
          mhGzts: '',
          mhLc: '',
          mhLk: '',
          mhLx: '',
          mhDlz: '',
          mhYf: '',
          mhZmcl: '',
          mhMklz: '',
          mhZqd: '',
          mhBqd: '',
          mhSzl: '',
          mhFsl: '',
          mhHd: '',
          mhYz: '',
          mhZz: '',
          addUser: ''
        },
        dataRule: {
          mhBh: [
            { required: true, message: '编号不能为空', trigger: 'blur' }
          ],
          recordDate: [
            { required: true, message: '记录日期，精确到天不能为空', trigger: 'blur' }
          ],
          mhNumber: [
            { required: true, message: '总株数不能为空', trigger: 'blur' }
          ],
          mhHeight: [
            { required: true, message: '株高不能为空', trigger: 'blur' }
          ],
          mhJc: [
            { required: true, message: '茎粗不能为空', trigger: 'blur' }
          ],
          mhYps: [
            { required: true, message: '叶片数不能为空', trigger: 'blur' }
          ],
          mhDygzjgd: [
            { required: true, message: '第一果枝节高度不能为空', trigger: 'blur' }
          ],
          mhGzs: [
            { required: true, message: '果枝数不能为空', trigger: 'blur' }
          ],
          mhLs: [
            { required: true, message: '蕾数不能为空', trigger: 'blur' }
          ],
          mhHs: [
            { required: true, message: '花数不能为空', trigger: 'blur' }
          ],
          mhZls: [
            { required: true, message: '总铃数不能为空', trigger: 'blur' }
          ],
          mhTxs: [
            { required: true, message: '吐絮数不能为空', trigger: 'blur' }
          ],
          mhGzsj: [
            { required: true, message: '果枝始节不能为空', trigger: 'blur' }
          ],
          mhGzts: [
            { required: true, message: '果枝台数不能为空', trigger: 'blur' }
          ],
          mhLc: [
            { required: true, message: '铃长不能为空', trigger: 'blur' }
          ],
          mhLk: [
            { required: true, message: '铃宽不能为空', trigger: 'blur' }
          ],
          mhLx: [
            { required: true, message: '铃型不能为空', trigger: 'blur' }
          ],
          mhDlz: [
            { required: true, message: '单铃重（克）不能为空', trigger: 'blur' }
          ],
          mhYf: [
            { required: true, message: '衣分（%）不能为空', trigger: 'blur' }
          ],
          mhZmcl: [
            { required: true, message: '籽棉产量不能为空', trigger: 'blur' }
          ],
          mhMklz: [
            { required: true, message: '马克隆值不能为空', trigger: 'blur' }
          ],
          mhZqd: [
            { required: true, message: '整齐度不能为空', trigger: 'blur' }
          ],
          mhBqd: [
            { required: true, message: '比强度不能为空', trigger: 'blur' }
          ],
          mhSzl: [
            { required: true, message: '伸长率不能为空', trigger: 'blur' }
          ],
          mhFsl: [
            { required: true, message: '反射率不能为空', trigger: 'blur' }
          ],
          mhHd: [
            { required: true, message: '黄度不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      activated () {
        this.getDataList()
      },
      init (id) {
        this.dataForm.mhId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.mhId) {
            this.$http({
              url: this.$http.adornUrl(`/mh/growth/info/${this.dataForm.mhId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.mhBh = data.growth.mhBh
                this.dataForm.recordDate = data.growth.recordDate
                this.dataForm.mhNumber = data.growth.mhNumber
                this.dataForm.mhHeight = data.growth.mhHeight
                this.dataForm.mhJc = data.growth.mhJc
                this.dataForm.mhYps = data.growth.mhYps
                this.dataForm.mhDygzjgd = data.growth.mhDygzjgd
                this.dataForm.mhGzs = data.growth.mhGzs
                this.dataForm.mhLs = data.growth.mhLs
                this.dataForm.mhHs = data.growth.mhHs
                this.dataForm.mhZls = data.growth.mhZls
                this.dataForm.mhDzjls = data.growth.mhDzjls
                this.dataForm.mhTxs = data.growth.mhTxs
                this.dataForm.mhGzsj = data.growth.mhGzsj
                this.dataForm.mhGzts = data.growth.mhGzts
                this.dataForm.mhLc = data.growth.mhLc
                this.dataForm.mhLk = data.growth.mhLk
                this.dataForm.mhLx = data.growth.mhLx
                this.dataForm.mhDlz = data.growth.mhDlz
                this.dataForm.mhYf = data.growth.mhYf
                this.dataForm.mhZmcl = data.growth.mhZmcl
                this.dataForm.mhMklz = data.growth.mhMklz
                this.dataForm.mhZqd = data.growth.mhZqd
                this.dataForm.mhBqd = data.growth.mhBqd
                this.dataForm.mhSzl = data.growth.mhSzl
                this.dataForm.mhFsl = data.growth.mhFsl
                this.dataForm.mhHd = data.growth.mhHd
                this.dataForm.mhYz = data.growth.mhYz
                this.dataForm.mhZz = data.growth.mhZz
                this.dataForm.addUser = data.growth.addUser
              }
            })
          }
        })
      },
      //  获得当前时间
      getCurrentTime () {
        return new Date()
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/mh/growth/${!this.dataForm.mhId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'mhId': this.dataForm.mhId || undefined,
                'mhBh': this.dataForm.mhBh,
                'recordDate': this.getCurrentTime(),
                'mhNumber': this.dataForm.mhNumber,
                'mhHeight': this.dataForm.mhHeight,
                'mhJc': this.dataForm.mhJc,
                'mhYps': this.dataForm.mhYps,
                'mhDygzjgd': this.dataForm.mhDygzjgd,
                'mhGzs': this.dataForm.mhGzs,
                'mhLs': this.dataForm.mhLs,
                'mhHs': this.dataForm.mhHs,
                'mhZls': this.dataForm.mhZls,
                'mhDzjls': this.dataForm.mhDzjls,
                'mhTxs': this.dataForm.mhTxs,
                'mhGzsj': this.dataForm.mhGzsj,
                'mhGzts': this.dataForm.mhGzts,
                'mhLc': this.dataForm.mhLc,
                'mhLk': this.dataForm.mhLk,
                'mhLx': this.dataForm.mhLx,
                'mhDlz': this.dataForm.mhDlz,
                'mhYf': this.dataForm.mhYf,
                'mhZmcl': this.dataForm.mhZmcl,
                'mhMklz': this.dataForm.mhMklz,
                'mhZqd': this.dataForm.mhZqd,
                'mhBqd': this.dataForm.mhBqd,
                'mhSzl': this.dataForm.mhSzl,
                'mhFsl': this.dataForm.mhFsl,
                'mhHd': this.dataForm.mhHd,
                'mhYz': this.dataForm.mhYz,
                'mhZz': this.dataForm.mhZz,
                'addUser': this.$store.state.user.name
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    location.reload()
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

